package api

import (
	"os"
	"fmt"
	. "kumachan/interpreter/runtime/def"
	"kumachan/interpreter/runtime/lib/debug"
)

var DebuggingFunctions = map[string] interface{} {
	"trace": func(v Value, h InteropContext) Value {
		const bold = "\033[1m"
		const reset = "\033[0m"
		var repr = debug.InspectUntypedValue(v)
		var loc, ok = h.Location()
		if ok {
			var loc = loc.SourceLocation()
			fmt.Fprintf (
				os.Stderr, "--- %vtrace:%v %s at %s\n",
				bold, reset, loc.PosDesc(), loc.FilePath(),
			)
		} else {
			fmt.Fprintf (
				os.Stderr, "--- %vtrace:%v top-level\n",
				bold, reset,
			)
		}
		fmt.Fprintf(os.Stderr, "%s\n", repr)
		return v
	},
}


